<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<body>
<script type="text/javascript">
$(function() {
	//alert('ok');
	djt_AD_editIndex = undefined;
	
	$('#djt_AD_dg').datagrid({
    	url:'../AbsenceDeduct/querybypage',
    	columns:[[
    		{field:'',title:'',checkbox:true},
			{field:'absenceDeductId',title:'编号',width:'50',sortable:true},
			{field:'absenceDeductType',title:'扣款类型',width:'150',editor:{type:'text',options:{required:true}}},
			{field:'absenceDeductValue',title:'扣款值（每次）',width:'150',editor:{type:'numberbox',options:{required:true,precision:2}}}
		]],
		fit:true,
 	   	fitColumns:false,
 	   	//隔行变色
 	   	striped:true,
  	  	nowrap:true,
		toolbar:'#ADtb',
		pagination:true,
		pageSize:2,
		pageList:[2],
		border:false,
		sortName:'absenceDeductId',
		sortOrder:'asc',
		onAfterEdit : function(rowIndex,rowData,changes){
			var updated = $('#djt_AD_dg').datagrid('getChanges','updated');
			var url = '';
			if(updated.length > 0){
				url = '../AbsenceDeduct/update';
			}
			var djt_AD_rowData = JSON.stringify(rowData);
			$.post(url,{djt_AD_rowData},function(e){
				var info = JSON.parse(e);
				//console.log(info);
				if(info.success){
					$('#djt_AD_dg').datagrid('acceptChanges');
					$.messager.show({
						title:'成功',
						msg:info.msg,
					});
				}else{
					$('#djt_AD_dg').datagrid('rejectChanges');
					$.messager.alert('错误',info.msg,'error');
				}
			})
			djt_AD_editIndex = undefined;
			$('#djt_AD_dg').datagrid('unselectAll');
		},
		onDblClickRow : function(rowIndex,rowData){
			if(djt_AD_editIndex != undefined){
				$('#djt_AD_dg').datagrid('endEdit',djt_AD_editIndex);
				djt_AD_editIndex = undefined;
			}
			if(djt_AD_editIndex == undefined){
				$('#djt_AD_dg').datagrid('beginEdit',rowIndex);
				djt_AD_editIndex = rowIndex;
			}
		}
	});
	
	$('#saveSubsidy').bind('click', function(){
		var value = $('#SValue').numberbox('getValue');
		$.post('../AbsenceDeduct/updateSubsidy',{'value':value},function(e){
			var info = JSON.parse(e);
			//console.log(info);
			if(info.success){
				$.messager.show({
					title:'成功',
					msg:info.msg,
				});
			}else{
				$.messager.alert('错误',info.msg,'error');
			}
		})
	});
});

//保存
function saveAD(){
	$('#djt_AD_dg').datagrid('endEdit',djt_AD_editIndex);
}

//编辑
function editAD(){
	var rows = $('#djt_AD_dg').datagrid('getSelections');
	if(rows.length == 1){
		if(djt_AD_editIndex != undefined){
			$('#djt_AD_dg').datagrid('endEdit',djt_AD_editIndex);
		}
		if(djt_AD_editIndex == undefined){
			var index = $('#djt_AD_dg').datagrid('getRowIndex',rows[0]);
			$('#djt_AD_dg').datagrid('beginEdit',index);
			djt_AD_editIndex = index;
			$('#djt_AD_dg').datagrid('unselectAll');
		}
	}else{
		$.messager.show({
			title:'提示',
			msg:'一次只能编辑一行！',
		});
	}
}

//撤销编辑
function rejectAD(){
	djt_AD_editIndex = undefined;
	$('#djt_AD_dg').datagrid('rejectChanges');
	$('#djt_AD_dg').datagrid('unselectAll');
}

</script>

	<div class="easyui-layout" fit="true" border="false">
	<div data-options="region:'east',title:'全勤奖:'   " style="width	:180px;" >
		<h4>全勤奖值：</h4>
		<input id="SValue" type="text" class="easyui-numberbox" data-options="min:0" value="${SubsidyValue }">
		<a id="saveSubsidy" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">修改</a>
	</div>
	<div region="center" border="false">
		<table id="djt_AD_dg"></table>
	
		<div id="ADtb">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editAD()">编辑</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="saveAD()">保存</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="rejectAD()">撤销编辑</a>
		</div>
	</div>	
	</div>
</body>